var app = getApp();
// pages/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    account: '',
    password: ''
  },
  inputAccount:function(e){
    this.setData({account:e.detail.value.trim()})
  },
  inputPassword: function (e) {
    this.setData({password:e.detail.value.trim()})
  },
  enter:function(){
    var me=this;
    console.log(me.data.account, me.data.password);
    wx.request({
      url: 'https://wx.sencegroup.com/xingchen/api/zbds/shop/pushFlowInfo', //仅为示例，并非真实的接口地址
      data: {
        user_name: me.data.account,
        password: me.data.password,
      },
      method:'POST',
      header: {"Content-Type":"application/x-www-form-urlencoded"},
      success: function (res) {
        console.log(res);
        if(res.data.code==0){
          app.globalData.token = res.data.data.token;
          wx.setStorage({
            key: "account",
            data: me.data.account
          });
          wx.setStorage({
            key: "password",
            data: me.data.password
          });
          wx.navigateTo({
            url: '../list/list'
          });
        }else{
          wx.showToast({
            title: res.data.msg,
            icon:'none',
            duration: 2000
          })
        }
      },
      fail:function(res){
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    wx.getStorage({
      key: 'account',
      success: function (res) {
        that.setData({account:res.data})
      }
    });
    wx.getStorage({
      key: 'password',
      success: function (res) {
        that.setData({password: res.data })
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})